package com.dek.ssm.ch4.handler;

import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import org.apache.ibatis.type.JdbcType;
import org.apache.ibatis.type.MappedJdbcTypes;
import org.apache.ibatis.type.MappedTypes;
import org.apache.ibatis.type.TypeHandler;

import com.dek.ssm.ch4.utils.Sex;

@MappedTypes(Sex.class)
@MappedJdbcTypes(JdbcType.INTEGER)
public class SexTypeHandler implements TypeHandler<Sex> {

	@Override
	public void setParameter(PreparedStatement ps, int i, Sex parameter, JdbcType jdbcType) throws SQLException {
		ps.setInt(i, parameter.getId());
	}

	@Override
	public Sex getResult(ResultSet rs, String columnName) throws SQLException {
		int id = rs.getInt(columnName);
		return Sex.getSexById(id);
	}

	@Override
	public Sex getResult(ResultSet rs, int columnIndex) throws SQLException {
		int id = rs.getInt(columnIndex);
		return Sex.getSexById(id);
	}

	@Override
	public Sex getResult(CallableStatement cs, int columnIndex) throws SQLException {
		int id = cs.getInt(columnIndex);
		return Sex.getSexById(id);
	}

}
